<template>
  <div class="app-container">
    <u-page title="发券操作">
      <el-form ref="dialogForm" :model="dataForm" :rules="rules" label-position="left" label-width="120px" style="margin-left: 40px">

        <el-form-item prop="saleNo" label="账单号">
          <el-input v-model="dataForm.saleNo" placeholder="请输入账单号" clearable maxlength="50" show-word-limit  style="width: 400px"/>
        </el-form-item>

        <el-form-item prop="restaurant" label="自收银餐厅">
          <ues-restaurant v-model="dataForm.restaurant"/>
        </el-form-item>

        <el-form-item label="选择会员" prop="cardNo">
          <ues-member v-model="dataForm.cardNo" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submit">确认发放</el-button>
        </el-form-item>
      </el-form>
    </u-page>

  </div>
</template>

<script>
import uesMember from '@/components/member/uesMember'
import uesRestaurant from '../components/uesRestaurant'

export default {
  components: {
    uesMember, uesRestaurant
  },
  data() {
    return {
      api: this.$u.api.MarketCouponSendmanually,
      restaurantList: [],
      // 会员选择器弹窗状态
      dialogMemberChoose: false,
      dataForm: {
        cardNo: '',
        saleNo: '',
        restaurant: ''
      },
      // 验证规则
      rules: {
        restaurant: [
          { required: true, message: '请选择自收银餐厅', trigger: ['blur'] }
        ],
        cardNo: [
          { required: true, message: '请选择会员', trigger: ['blur'] }
        ],
        saleNo: [
          { required: true, message: '请输入账单号', trigger: ['blur'] }
        ]
      },
    }
  },
  methods: {
    // 监听优惠券列表
    changeCouponList(list) {
      this.dataForm.couponChooseList = list
    },
    // 确认发放
    submit() {
      const self = this

      // 效验数据格式
      self.$refs['dialogForm'].validate((valid) => {
        if (valid) {
          // 模态对话框组件
          self.$confirm('此操作将发放优惠券，是否继续？', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => {
            const d = self.$u.deepClone(self.dataForm)
            console.log(d)
            // 提交数据
            // self.api.submit(d).then(res => {
            //   // 初始化数据
            //   self.dataForm = {
            //     type: type,
            //     memberIds: '',
            //     oldOrderNo: '',
            //     note: '',
            //     couponId: ''
            //   }
            //   self.$refs.uesCoupon.reset()
            //   // 通知信息
            //   self.$u.msg('发放优惠券成功')
            //
            //   if (type === 2) {
            //     const { qrcode } = res.data
            //     self.qrcode = qrcode
            //   }
            // })
          }).catch(() => {
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .form-title {
    margin-bottom: 30px;
    font-size: 16px;
    font-weight: bold;
    line-height: 22px;
    padding: 9px 20px;
    background-color: #f4f4f5;
  }
</style>
